<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common" extension-element-prefixes="exsl" xmlns:pro="http://xml.netbeans.org/schema/products" xmlns:user="http://xml.netbeans.org/schema/users" xmlns:userdetail="http://xml.netbeans.org/schema/userdetails" xmlns:order="http://xml.netbeans.org/schema/orders" exclude-result-prefixes="pro user userdetail order" version="1.0">
    <xsl:output method="html" indent="yes" version="1.0"/>
    <xsl:param name="type" select="'containproduct'"/>
    <xsl:param name="contextpath" select="''"/>
    <xsl:param name="reportholder" select="''"/>
    <xsl:template match="/">
        <xsl:if test="$type='containuser'">
            <xsl:call-template name="containuser"/>
        </xsl:if>
        <xsl:if test="$type='inuser'">
            <xsl:call-template name="inuser"/>
        </xsl:if>
        <xsl:if test="$type='containproduct'">
            <xsl:call-template name="containproduct"/>
        </xsl:if>
        <xsl:if test="$type='inproduct'">
            <xsl:call-template name="inproduct"/>
        </xsl:if>
        <xsl:if test="$type='saveproduct'">
            <xsl:call-template name="saveproduct"/>
        </xsl:if>
        <xsl:if test="$type='report'">
            <xsl:call-template name="report"/>
        </xsl:if>
    </xsl:template>
    <xsl:template name="inuser">
        <div  class="manage-content">
            <table class="table-hover">
                <thead align="center">
                    <tr>
                        <th>Account</th>
                        <th>Role</th>
                        <th>IsActive</th>
                        <th>Detail</th>
                        <th>Activation</th>
                    </tr>
                </thead>
                <tbody align="center">
                     
                    <xsl:for-each select="user:Users/user:User">
                        <tr>
                            <td>
                                <div>
                                    <xsl:value-of select="user:Username"/>
                                </div>
                            </td>
                            <xsl:variable name="options">
                                <selected>
                                    <xsl:value-of select="user:RoleId"/>
                                </selected>
                                <opt>1</opt>
                                <opt>2</opt>
                                <opt>3</opt>
                                <opt>4</opt>
                            </xsl:variable>
                            <td>
                                <div>
                                    <select userid="{user:Id}" class="updateRole">
                                        <xsl:for-each select="exsl:node-set($options)/opt">
                                            
                                            <option value="{.}">
                                                <xsl:if test="exsl:node-set($options)/selected=.">
                                                    <xsl:attribute name="selected">
                                                        <xsl:text>selected</xsl:text>
                                                    </xsl:attribute>
                                                </xsl:if>
                                                <xsl:if test=".=1">
                                                        Admin
                                                    </xsl:if>
                                                <xsl:if test=".=2">
                                                    Customer
                                                </xsl:if>
                                                <xsl:if test=".=3">
                                                    Manager
                                                </xsl:if>
                                                <xsl:if test=".=4">
                                                    Anonymous
                                                </xsl:if>
                                            </option>
                                        </xsl:for-each>
                                    </select>
                                    
                                </div>
                            </td>
                            <td>
                                <div>
                                    <xsl:value-of select="user:IsActive"/>
                                </div>
                            </td>
                            <td>
                                <div>
                                    <a href="#" userdetailid="{user:UserDetailId}" class="btn btn-info linkDetail">View Detail</a>
                                </div>
                                
                            </td>
                            <td>
                                <xsl:if test="user:RoleId!='1'">
                                    <a>
                                        <xsl:attribute name="userid">
                                            <xsl:value-of select="user:Id"/>
                                        </xsl:attribute>
                                    
                                        <xsl:attribute name="class">
                                            <xsl:text>btn btn-info linkActive</xsl:text>
                                        </xsl:attribute>
                                        <xsl:choose>
                                            <xsl:when test="user:IsActive='true'">
                                                <xsl:text>Deactive</xsl:text>
                                            </xsl:when>
                                            <xsl:otherwise>
                                                <xsl:text>Active</xsl:text>
                                            </xsl:otherwise>
                                        </xsl:choose>
                                    </a>
                                </xsl:if>
                            </td>
                        </tr>
                    </xsl:for-each>
                </tbody>
            </table>
        </div>
    </xsl:template>
    <xsl:template name="containuser">
        <div id="error-container"></div>
        <div id="UserContainer"  class="manage-content">
            <xsl:call-template name="inuser"/>
        </div>
    </xsl:template>

    <xsl:template name="inproduct">
        <div  class="manage-content">
            <table border="1" class="table-hover">
                <thead align="center">
                    <tr>
                        <th>Name</th>
                        <th>Image</th>
                        <th>Description</th>
                        <th>Price</th>
                        <th>Status</th>
                        <th align="right">
                            <a>
                                <xsl:attribute name="href">
                                    <xsl:text>#</xsl:text>
                                </xsl:attribute>
                                <xsl:attribute name="proid">
                                    <xsl:value-of select="pro:Id"/>
                                </xsl:attribute>
                                <xsl:attribute name="class">
                                    <xsl:text>btn btn-success linkAdd</xsl:text>
                                </xsl:attribute>
                                <xsl:text>Add New</xsl:text>
                            </a>
                        </th>
                    </tr>
                </thead>
                <tbody align="center">
                    <xsl:for-each select="pro:Products/pro:Product">
                        <tr>
                            <td>
                                <div class="ProName">
                                    <xsl:value-of select="pro:Name"/>
                                </div>
                            </td>
                            <td>
                                <div class="ProImg">
                                    <img>
                                        <xsl:attribute name="src">
                                            <xsl:text>../</xsl:text>
                                            <xsl:value-of select="pro:ImageURL"/>
                                        </xsl:attribute>
                                        <xsl:attribute name="a">
                                            <xsl:text>Image cannot be displayed</xsl:text>
                                        </xsl:attribute>
                                    </img>
                                </div>
                            </td>
                            <td>
                                <div class="ProDescription">
                                    <xsl:value-of select="pro:Description"/>
                                </div>
                            </td>
                            <td>
                                <div class="ProPrice">
                                    <xsl:value-of select="pro:Price"/>
                                </div>
                            </td>
                            <td>
                                <div class="ProIsActive">
                                    <xsl:value-of select="pro:IsActive"/>
                                </div>
                            </td>
                            <td>
                                <div class="btn-group dropup">
                                    <button>
                                        <xsl:attribute name="proid">
                                            <xsl:value-of select="pro:Id"/>
                                        </xsl:attribute>
                                        <xsl:attribute name="class">
                                            <xsl:text>btn btn-info linkUpdate</xsl:text>
                                        </xsl:attribute>
                                        <xsl:text>Update</xsl:text>
                                    </button>
                                    <button class="btn btn-info dropdown-toggle" data-toggle="dropdown">
                                        <span class="caret"></span>
                                    </button>
                                    <ul class="dropdown-menu">
                                        <li>
                                            <a>
                                                <xsl:attribute name="href">
                                                    <xsl:text>#</xsl:text>
                                                </xsl:attribute>
                                                <xsl:attribute name="proid">
                                                    <xsl:value-of select="pro:Id"/>
                                                </xsl:attribute>
                                                <xsl:attribute name="class">
                                                    <xsl:text>linkActive</xsl:text>
                                                </xsl:attribute>
                                                <xsl:choose>
                                                    <xsl:when test="pro:IsActive='true'">
                                                        <xsl:text>Deactive</xsl:text>
                                                    </xsl:when>
                                                    <xsl:otherwise>
                                                        <xsl:text>Active</xsl:text>
                                                    </xsl:otherwise>
                                                </xsl:choose>
                                            </a>
                                        </li>
                                        <li>
                                            <a>
                                                <xsl:attribute name="href">
                                                    <xsl:text>#</xsl:text>
                                                </xsl:attribute>
                                                <xsl:attribute name="proid">
                                                    <xsl:value-of select="pro:Id" />
                                                </xsl:attribute>
                                                <xsl:attribute name="proname">
                                                    <xsl:value-of select="pro:Name"/>
                                                </xsl:attribute>
                                                <xsl:attribute name="class">
                                                    <xsl:text>ViewComments</xsl:text>
                                                </xsl:attribute>
                                                <xsl:text>Comments</xsl:text>
                                            </a>
                                        </li>
                                    </ul>
                                </div>
                            </td>
                        </tr>
                    </xsl:for-each>
                </tbody>
            </table>
        </div>
    </xsl:template>
    <xsl:template name="containproduct">
        <div id="error-container"></div>
        <div id="ProductContainer" class="manage-content">
            <xsl:call-template name="inproduct"/>
        </div>
    </xsl:template>

    <xsl:template name="saveproduct">
        <div id="NewProductContainer">
            <h3>Add Product</h3>
            <br/>
            <table border="1" class="table table-hover">
                
                <tbody>
                    <tr>
                        <td>
                            <b>Name:</b>
                        </td>
                        <td>
                            <input type="text" id="txtName" value="" /> *
                            <div id="error-Name"></div>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <b>ImageUrl:</b>
                        </td>
                        <td>
                            <input type="text" id="txtImageUrl" value="" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <b>Price:</b>
                        </td>
                        <td>
                            <input type="text" id="txtPrice" value="" /> *
                            <div id="error-Price"></div>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <b>Description:</b>
                        </td>
                        <td>
<!--                            <input type="text" id="txtIntroduction" value="" />-->
                            <textarea id="txtDescription" class="comment-text"></textarea>
                        </td>
                    </tr>
                </tbody>
            </table>
            <a href="#" id="saveProduct" class="btn btn-success">Save</a>
        </div>
    </xsl:template>

    <xsl:template name="report">
        <div  class="manage-content" >
            <table border="1" class="table-hover">
                <thead>
                    <tr>
                        <th>Report</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>
                            <a href="{$contextpath}/{$reportholder}?action=ON_PRODUCT">List: Best Product</a>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <a href="{$contextpath}/{$reportholder}?action=ON_USER">List: Golden User </a>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
    </xsl:template>
</xsl:stylesheet>
